from typing import Protocol, runtime_checkable

# 定义协议
class Drawable(Protocol):
    def draw(self) -> None: ...

# 使用@runtime_checkable装饰器可以在运行时检查
@runtime_checkable
class Sized(Protocol):
    def __len__(self) -> int: ...

# 实现协议的类 (无需显式继承)
class Circle:
    def __init__(self, radius: float):
        self.radius = radius
        
    def draw(self) -> None:
        print(f"Drawing a circle with radius {self.radius}")

# 使用协议作为类型约束
def render(obj: Drawable) -> None:
    obj.draw()

# 运行时检查
def check_sized(obj: object) -> None:
    if isinstance(obj, Sized):
        print(f"Object has length: {len(obj)}")
    else:
        print("Object does not support len()")